package com.gitee.wsl.common.ui.symbol.particle

import androidx.compose.ui.graphics.Color
import com.gitee.wsl.common.ui.base.Point
import com.gitee.wsl.math.degreesToRadians
import kotlin.math.cos
import kotlin.math.sin

open class ToPointParticle(
     startX: Float = 0f,
     startY: Float = 0f,
    val angle: Int = 0,
    var dis: Float = 1f,
     size: Float = 5f,
     color: Color = Color.Red,
     alpha: Float = 1f
):Particle(startX, startY, size, color,alpha) {
    constructor(start:Point,
                angle: Int = 0,
                dis: Float = 1f,
                size: Float = 5f,
                color: Color = Color.Red,
                alpha: Float = 1f):this(start.x,start.y,angle, dis, size, color, alpha)

    var endx: Float = 0f
    var endy: Float = 0f

    init {
        endx = pointX(dis, startX, angle.toFloat())
        endy = pointY(dis, startY, angle.toFloat())
    }

    fun update() {
        endx = pointX(dis, endx, angle.toFloat())
        endy = pointY(dis, endy, angle.toFloat())
        alpha -= 0.02f
        if (alpha < 0) {
            alpha = 0f
        }
        size -= 0.5f
        if (size < 0f) {
            size = 0f
        }
    }
}

internal fun pointX(radius: Float, centerX: Float, angle: Float): Float {
    val res = angle.degreesToRadians()
    return centerX - cos(res) * (radius)
}

internal fun pointY(radius: Float, centerY: Float, angle: Float): Float {
    val res = angle.degreesToRadians()
    return centerY - sin(res) * (radius)
}